<extend name="./Application/Admin/View/Layout/application.html"/>

<block name="css">
    <link rel="stylesheet" href="__PUBLIC__/assets/admin/css/common.css"/>
</block>

<block name="content">
    <!-- content start -->
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品分类管理</strong> /
                    <small>Good Categories Manage</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a class="am-btn am-btn-default" href="{{:U('add')}}"><span class="am-icon-plus">新增</span>
                            </a>


                            <button class="am-btn am-btn-success" id="show_all" href=""><span
                                    class="am-icon-arrows-alt">展开所有</span></button>

                        </div>
                    </div>
                </div>


            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox"/></th>
                                <th class="table-id">编号</th>
                                <th class="table-title">分类名</th>
                                <th class="table-type">分类商品</th>
                                <th class="table-author am-hide-sm-only">是否显示</th>
                                <th class="table-date am-hide-sm-only">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <volist name="categories" id="category">
                                <tr data-id="{{$category.id}}" class="xParent">
                                    <td><input type="checkbox"/></td>
                                    <td>{{$category.id}}</td>
                                    <td><a href="#">{{$category.name}}</a></td>
                                    <td>
                                    </td>
                                    <td class="am-hide-sm-only" data-attr="{{$category.is_show}}">
                                        <eq name="category.is_show" value="1">
                                            <span class="am-icon-check is_show"></span>
                                            <else/>
                                            <span class="am-icon-close is_show"></span>
                                        </eq>

                                    </td>
                                    <td class="am-hide-sm-only">
                                        <input type="text" id="sort_one" class=" sort_order form-control"
                                               value="{{$category.sort_order}}" style="width: 50px;">

                                    </td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                        class="am-icon-pencil-square-o"></span> <a
                                                        href="{{:U('edit',['id'=>$category[id]])}}">编辑</a>
                                                </button>

                                                <a href="javascript:;"
                                                   class=" delete_category am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                            </div>
                                        </div>
                                    </td>
                                </tr>


                                <volist name="category.children" id="child">
                                    <tr data-id="{{$child.id}}" class="xChildren" style="display: none">
                                        <td><input type="checkbox"/></td>
                                        <td>{{$child.id}}</td>
                                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$child.name}}</a></td>
                                        <td><a href="{{:U('Product/index',['category_id'=>$child[id]])}}" class="am-btn am-btn-primary am-btn-xs look_product">查看商品</a>
                                        </td>
                                        <td class="am-hide-sm-only" data-attr="{{$child.is_show}}">
                                            <eq name="child.is_show" value="1">
                                                <span class="am-icon-check is_show"></span>
                                                <else/>
                                                <span class="am-icon-close is_show"></span>
                                            </eq>

                                        </td>
                                        <td class="am-hide-sm-only">
                                            <input type="text" id="sort_two" class=" sort_order form-control"
                                                   value="{{$child.sort_order}}" style="width: 50px;"></td>
                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span
                                                            class="am-icon-pencil-square-o"></span><a
                                                            href="{{:U('edit',['id'=>$child[id]])}}">编辑</a>
                                                    </button>

                                                    <a href="javascript:;"
                                                       class=" delete_category am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only">
                                                        <span class="am-icon-trash-o"></span> 删除
                                                    </a>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </volist>
                            </volist>


                            </tbody>
                        </table>
                        <div class="am-cf">
                            共 {{$count}}条记录
                            <div class="am-fr">
                                <ul class="am-pagination">
                                    {{$page}}
                                </ul>
                            </div>
                        </div>
                        <hr/>
                        <p>注：.....</p>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>
    <!-- content end -->
</block>
<block name="js">
    <script>
        $(function () {
            //ajax删除
            $('.delete_category').click(function () {
                if (confirm('确认删除此广告吗？')){
                    var id = $(this).parents('tr').data('id');
                    var _this = $(this);
                    $.post("{{:U('delete')}}", {id: id}, function (info) {
                        if (info.status == 1) {
                            alert(info.msg);
                            _this.parents('tr').fadeOut(400);
                        } else {
                            alert(info.msg)
                        }
                    })
                    return false;
                }

            })

            //是否显示
            $('.is_show').click(function () {
                var id = $(this).parents('tr').data('id');
                var is_show = $(this).parents('td').attr('data-attr');
                var _this = $(this);
                $.post("{{:U('change_attr')}}", {id: id, is_show: is_show}, function () {
                    _this.toggleClass('am-icon-check am-icon-close');
                })
                return false;
            })
            //排序
            $('.sort_order').change(function () {
                var info = {
                    id: $(this).parents('tr').data('id'),
                    sort_order: $(this).val()
                }
                $.post("{{:U('ajax_order')}}", info, function () {
                    location.href = "{{:U('Category/index')}}"
                })
                return false;
            })
            //展开与折叠表格
            $('tr.xParent').dblclick(function () {
                $(this).toggleClass();
                $(".child_" + this.id).toggle();

            })
            $('#show_all').click(function () {
                $('tr.xParent').toggleClass();

                $('tr.xChildren').toggle('am-active');
            })


        })
    </script>


</block>
